package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.MyFavorite;
import com.xjgzinfo.usdp.repository.MyFavoriteRepository;
import com.xjgzinfo.usdp.service.MyFavoriteService;
import com.xjgzinfo.usdp.service.dto.MyFavoriteDTO;
import com.xjgzinfo.usdp.service.mapper.MyFavoriteMapper;
import com.xjgzinfo.usdp.service.dto.MyFavoriteCriteria;
import com.xjgzinfo.usdp.service.MyFavoriteQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link MyFavoriteResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class MyFavoriteResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_TYPE = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final Double DEFAULT_SCORE = 1D;
    private static final Double UPDATED_SCORE = 2D;
    private static final Double SMALLER_SCORE = 1D - 1D;

    private static final Long DEFAULT_USER_ID = 1L;
    private static final Long UPDATED_USER_ID = 2L;
    private static final Long SMALLER_USER_ID = 1L - 1L;

    private static final Long DEFAULT_RESOURCE_ID = 1L;
    private static final Long UPDATED_RESOURCE_ID = 2L;
    private static final Long SMALLER_RESOURCE_ID = 1L - 1L;

    @Autowired
    private MyFavoriteRepository myFavoriteRepository;

    @Autowired
    private MyFavoriteMapper myFavoriteMapper;

    @Autowired
    private MyFavoriteService myFavoriteService;

    @Autowired
    private MyFavoriteQueryService myFavoriteQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restMyFavoriteMockMvc;

    private MyFavorite myFavorite;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static MyFavorite createEntity(EntityManager em) {
        MyFavorite myFavorite = new MyFavorite()
            .name(DEFAULT_NAME)
            .type(DEFAULT_TYPE)
            .createTime(DEFAULT_CREATE_TIME)
            .score(DEFAULT_SCORE)
            .userId(DEFAULT_USER_ID)
            .resourceId(DEFAULT_RESOURCE_ID);
        return myFavorite;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static MyFavorite createUpdatedEntity(EntityManager em) {
        MyFavorite myFavorite = new MyFavorite()
            .name(UPDATED_NAME)
            .type(UPDATED_TYPE)
            .createTime(UPDATED_CREATE_TIME)
            .score(UPDATED_SCORE)
            .userId(UPDATED_USER_ID)
            .resourceId(UPDATED_RESOURCE_ID);
        return myFavorite;
    }

    @BeforeEach
    public void initTest() {
        myFavorite = createEntity(em);
    }

    @Test
    @Transactional
    public void createMyFavorite() throws Exception {
        int databaseSizeBeforeCreate = myFavoriteRepository.findAll().size();
        // Create the MyFavorite
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);
        restMyFavoriteMockMvc.perform(post("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isCreated());

        // Validate the MyFavorite in the database
        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeCreate + 1);
        MyFavorite testMyFavorite = myFavoriteList.get(myFavoriteList.size() - 1);
        assertThat(testMyFavorite.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testMyFavorite.getType()).isEqualTo(DEFAULT_TYPE);
        assertThat(testMyFavorite.getCreateTime()).isEqualTo(DEFAULT_CREATE_TIME);
        assertThat(testMyFavorite.getScore()).isEqualTo(DEFAULT_SCORE);
        assertThat(testMyFavorite.getUserId()).isEqualTo(DEFAULT_USER_ID);
        assertThat(testMyFavorite.getResourceId()).isEqualTo(DEFAULT_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void createMyFavoriteWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = myFavoriteRepository.findAll().size();

        // Create the MyFavorite with an existing ID
        myFavorite.setId(1L);
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);

        // An entity with an existing ID cannot be created, so this API call must fail
        restMyFavoriteMockMvc.perform(post("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isBadRequest());

        // Validate the MyFavorite in the database
        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = myFavoriteRepository.findAll().size();
        // set the field null
        myFavorite.setName(null);

        // Create the MyFavorite, which fails.
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);


        restMyFavoriteMockMvc.perform(post("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isBadRequest());

        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = myFavoriteRepository.findAll().size();
        // set the field null
        myFavorite.setType(null);

        // Create the MyFavorite, which fails.
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);


        restMyFavoriteMockMvc.perform(post("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isBadRequest());

        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkUserIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = myFavoriteRepository.findAll().size();
        // set the field null
        myFavorite.setUserId(null);

        // Create the MyFavorite, which fails.
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);


        restMyFavoriteMockMvc.perform(post("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isBadRequest());

        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllMyFavorites() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList
        restMyFavoriteMockMvc.perform(get("/api/my-favorites?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(myFavorite.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].score").value(hasItem(DEFAULT_SCORE.doubleValue())))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].resourceId").value(hasItem(DEFAULT_RESOURCE_ID.intValue())));
    }
    
    @Test
    @Transactional
    public void getMyFavorite() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get the myFavorite
        restMyFavoriteMockMvc.perform(get("/api/my-favorites/{id}", myFavorite.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(myFavorite.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.type").value(DEFAULT_TYPE))
            .andExpect(jsonPath("$.createTime").value(DEFAULT_CREATE_TIME.toString()))
            .andExpect(jsonPath("$.score").value(DEFAULT_SCORE.doubleValue()))
            .andExpect(jsonPath("$.userId").value(DEFAULT_USER_ID.intValue()))
            .andExpect(jsonPath("$.resourceId").value(DEFAULT_RESOURCE_ID.intValue()));
    }


    @Test
    @Transactional
    public void getMyFavoritesByIdFiltering() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        Long id = myFavorite.getId();

        defaultMyFavoriteShouldBeFound("id.equals=" + id);
        defaultMyFavoriteShouldNotBeFound("id.notEquals=" + id);

        defaultMyFavoriteShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultMyFavoriteShouldNotBeFound("id.greaterThan=" + id);

        defaultMyFavoriteShouldBeFound("id.lessThanOrEqual=" + id);
        defaultMyFavoriteShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllMyFavoritesByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name equals to DEFAULT_NAME
        defaultMyFavoriteShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the myFavoriteList where name equals to UPDATED_NAME
        defaultMyFavoriteShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name not equals to DEFAULT_NAME
        defaultMyFavoriteShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the myFavoriteList where name not equals to UPDATED_NAME
        defaultMyFavoriteShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByNameIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name in DEFAULT_NAME or UPDATED_NAME
        defaultMyFavoriteShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the myFavoriteList where name equals to UPDATED_NAME
        defaultMyFavoriteShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name is not null
        defaultMyFavoriteShouldBeFound("name.specified=true");

        // Get all the myFavoriteList where name is null
        defaultMyFavoriteShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllMyFavoritesByNameContainsSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name contains DEFAULT_NAME
        defaultMyFavoriteShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the myFavoriteList where name contains UPDATED_NAME
        defaultMyFavoriteShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByNameNotContainsSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where name does not contain DEFAULT_NAME
        defaultMyFavoriteShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the myFavoriteList where name does not contain UPDATED_NAME
        defaultMyFavoriteShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllMyFavoritesByTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type equals to DEFAULT_TYPE
        defaultMyFavoriteShouldBeFound("type.equals=" + DEFAULT_TYPE);

        // Get all the myFavoriteList where type equals to UPDATED_TYPE
        defaultMyFavoriteShouldNotBeFound("type.equals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByTypeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type not equals to DEFAULT_TYPE
        defaultMyFavoriteShouldNotBeFound("type.notEquals=" + DEFAULT_TYPE);

        // Get all the myFavoriteList where type not equals to UPDATED_TYPE
        defaultMyFavoriteShouldBeFound("type.notEquals=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByTypeIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type in DEFAULT_TYPE or UPDATED_TYPE
        defaultMyFavoriteShouldBeFound("type.in=" + DEFAULT_TYPE + "," + UPDATED_TYPE);

        // Get all the myFavoriteList where type equals to UPDATED_TYPE
        defaultMyFavoriteShouldNotBeFound("type.in=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByTypeIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type is not null
        defaultMyFavoriteShouldBeFound("type.specified=true");

        // Get all the myFavoriteList where type is null
        defaultMyFavoriteShouldNotBeFound("type.specified=false");
    }
                @Test
    @Transactional
    public void getAllMyFavoritesByTypeContainsSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type contains DEFAULT_TYPE
        defaultMyFavoriteShouldBeFound("type.contains=" + DEFAULT_TYPE);

        // Get all the myFavoriteList where type contains UPDATED_TYPE
        defaultMyFavoriteShouldNotBeFound("type.contains=" + UPDATED_TYPE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByTypeNotContainsSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where type does not contain DEFAULT_TYPE
        defaultMyFavoriteShouldNotBeFound("type.doesNotContain=" + DEFAULT_TYPE);

        // Get all the myFavoriteList where type does not contain UPDATED_TYPE
        defaultMyFavoriteShouldBeFound("type.doesNotContain=" + UPDATED_TYPE);
    }


    @Test
    @Transactional
    public void getAllMyFavoritesByCreateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where createTime equals to DEFAULT_CREATE_TIME
        defaultMyFavoriteShouldBeFound("createTime.equals=" + DEFAULT_CREATE_TIME);

        // Get all the myFavoriteList where createTime equals to UPDATED_CREATE_TIME
        defaultMyFavoriteShouldNotBeFound("createTime.equals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByCreateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where createTime not equals to DEFAULT_CREATE_TIME
        defaultMyFavoriteShouldNotBeFound("createTime.notEquals=" + DEFAULT_CREATE_TIME);

        // Get all the myFavoriteList where createTime not equals to UPDATED_CREATE_TIME
        defaultMyFavoriteShouldBeFound("createTime.notEquals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByCreateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where createTime in DEFAULT_CREATE_TIME or UPDATED_CREATE_TIME
        defaultMyFavoriteShouldBeFound("createTime.in=" + DEFAULT_CREATE_TIME + "," + UPDATED_CREATE_TIME);

        // Get all the myFavoriteList where createTime equals to UPDATED_CREATE_TIME
        defaultMyFavoriteShouldNotBeFound("createTime.in=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByCreateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where createTime is not null
        defaultMyFavoriteShouldBeFound("createTime.specified=true");

        // Get all the myFavoriteList where createTime is null
        defaultMyFavoriteShouldNotBeFound("createTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score equals to DEFAULT_SCORE
        defaultMyFavoriteShouldBeFound("score.equals=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score equals to UPDATED_SCORE
        defaultMyFavoriteShouldNotBeFound("score.equals=" + UPDATED_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score not equals to DEFAULT_SCORE
        defaultMyFavoriteShouldNotBeFound("score.notEquals=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score not equals to UPDATED_SCORE
        defaultMyFavoriteShouldBeFound("score.notEquals=" + UPDATED_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score in DEFAULT_SCORE or UPDATED_SCORE
        defaultMyFavoriteShouldBeFound("score.in=" + DEFAULT_SCORE + "," + UPDATED_SCORE);

        // Get all the myFavoriteList where score equals to UPDATED_SCORE
        defaultMyFavoriteShouldNotBeFound("score.in=" + UPDATED_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score is not null
        defaultMyFavoriteShouldBeFound("score.specified=true");

        // Get all the myFavoriteList where score is null
        defaultMyFavoriteShouldNotBeFound("score.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score is greater than or equal to DEFAULT_SCORE
        defaultMyFavoriteShouldBeFound("score.greaterThanOrEqual=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score is greater than or equal to UPDATED_SCORE
        defaultMyFavoriteShouldNotBeFound("score.greaterThanOrEqual=" + UPDATED_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score is less than or equal to DEFAULT_SCORE
        defaultMyFavoriteShouldBeFound("score.lessThanOrEqual=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score is less than or equal to SMALLER_SCORE
        defaultMyFavoriteShouldNotBeFound("score.lessThanOrEqual=" + SMALLER_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsLessThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score is less than DEFAULT_SCORE
        defaultMyFavoriteShouldNotBeFound("score.lessThan=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score is less than UPDATED_SCORE
        defaultMyFavoriteShouldBeFound("score.lessThan=" + UPDATED_SCORE);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByScoreIsGreaterThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where score is greater than DEFAULT_SCORE
        defaultMyFavoriteShouldNotBeFound("score.greaterThan=" + DEFAULT_SCORE);

        // Get all the myFavoriteList where score is greater than SMALLER_SCORE
        defaultMyFavoriteShouldBeFound("score.greaterThan=" + SMALLER_SCORE);
    }


    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId equals to DEFAULT_USER_ID
        defaultMyFavoriteShouldBeFound("userId.equals=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId equals to UPDATED_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.equals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId not equals to DEFAULT_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.notEquals=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId not equals to UPDATED_USER_ID
        defaultMyFavoriteShouldBeFound("userId.notEquals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId in DEFAULT_USER_ID or UPDATED_USER_ID
        defaultMyFavoriteShouldBeFound("userId.in=" + DEFAULT_USER_ID + "," + UPDATED_USER_ID);

        // Get all the myFavoriteList where userId equals to UPDATED_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.in=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId is not null
        defaultMyFavoriteShouldBeFound("userId.specified=true");

        // Get all the myFavoriteList where userId is null
        defaultMyFavoriteShouldNotBeFound("userId.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId is greater than or equal to DEFAULT_USER_ID
        defaultMyFavoriteShouldBeFound("userId.greaterThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId is greater than or equal to UPDATED_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.greaterThanOrEqual=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId is less than or equal to DEFAULT_USER_ID
        defaultMyFavoriteShouldBeFound("userId.lessThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId is less than or equal to SMALLER_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.lessThanOrEqual=" + SMALLER_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsLessThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId is less than DEFAULT_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.lessThan=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId is less than UPDATED_USER_ID
        defaultMyFavoriteShouldBeFound("userId.lessThan=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByUserIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where userId is greater than DEFAULT_USER_ID
        defaultMyFavoriteShouldNotBeFound("userId.greaterThan=" + DEFAULT_USER_ID);

        // Get all the myFavoriteList where userId is greater than SMALLER_USER_ID
        defaultMyFavoriteShouldBeFound("userId.greaterThan=" + SMALLER_USER_ID);
    }


    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId equals to DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.equals=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId equals to UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.equals=" + UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId not equals to DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.notEquals=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId not equals to UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.notEquals=" + UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsInShouldWork() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId in DEFAULT_RESOURCE_ID or UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.in=" + DEFAULT_RESOURCE_ID + "," + UPDATED_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId equals to UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.in=" + UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId is not null
        defaultMyFavoriteShouldBeFound("resourceId.specified=true");

        // Get all the myFavoriteList where resourceId is null
        defaultMyFavoriteShouldNotBeFound("resourceId.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId is greater than or equal to DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.greaterThanOrEqual=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId is greater than or equal to UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.greaterThanOrEqual=" + UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId is less than or equal to DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.lessThanOrEqual=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId is less than or equal to SMALLER_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.lessThanOrEqual=" + SMALLER_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsLessThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId is less than DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.lessThan=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId is less than UPDATED_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.lessThan=" + UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyFavoritesByResourceIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        // Get all the myFavoriteList where resourceId is greater than DEFAULT_RESOURCE_ID
        defaultMyFavoriteShouldNotBeFound("resourceId.greaterThan=" + DEFAULT_RESOURCE_ID);

        // Get all the myFavoriteList where resourceId is greater than SMALLER_RESOURCE_ID
        defaultMyFavoriteShouldBeFound("resourceId.greaterThan=" + SMALLER_RESOURCE_ID);
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultMyFavoriteShouldBeFound(String filter) throws Exception {
        restMyFavoriteMockMvc.perform(get("/api/my-favorites?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(myFavorite.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].type").value(hasItem(DEFAULT_TYPE)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].score").value(hasItem(DEFAULT_SCORE.doubleValue())))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].resourceId").value(hasItem(DEFAULT_RESOURCE_ID.intValue())));

        // Check, that the count call also returns 1
        restMyFavoriteMockMvc.perform(get("/api/my-favorites/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultMyFavoriteShouldNotBeFound(String filter) throws Exception {
        restMyFavoriteMockMvc.perform(get("/api/my-favorites?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restMyFavoriteMockMvc.perform(get("/api/my-favorites/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingMyFavorite() throws Exception {
        // Get the myFavorite
        restMyFavoriteMockMvc.perform(get("/api/my-favorites/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateMyFavorite() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        int databaseSizeBeforeUpdate = myFavoriteRepository.findAll().size();

        // Update the myFavorite
        MyFavorite updatedMyFavorite = myFavoriteRepository.findById(myFavorite.getId()).get();
        // Disconnect from session so that the updates on updatedMyFavorite are not directly saved in db
        em.detach(updatedMyFavorite);
        updatedMyFavorite
            .name(UPDATED_NAME)
            .type(UPDATED_TYPE)
            .createTime(UPDATED_CREATE_TIME)
            .score(UPDATED_SCORE)
            .userId(UPDATED_USER_ID)
            .resourceId(UPDATED_RESOURCE_ID);
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(updatedMyFavorite);

        restMyFavoriteMockMvc.perform(put("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isOk());

        // Validate the MyFavorite in the database
        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeUpdate);
        MyFavorite testMyFavorite = myFavoriteList.get(myFavoriteList.size() - 1);
        assertThat(testMyFavorite.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testMyFavorite.getType()).isEqualTo(UPDATED_TYPE);
        assertThat(testMyFavorite.getCreateTime()).isEqualTo(UPDATED_CREATE_TIME);
        assertThat(testMyFavorite.getScore()).isEqualTo(UPDATED_SCORE);
        assertThat(testMyFavorite.getUserId()).isEqualTo(UPDATED_USER_ID);
        assertThat(testMyFavorite.getResourceId()).isEqualTo(UPDATED_RESOURCE_ID);
    }

    @Test
    @Transactional
    public void updateNonExistingMyFavorite() throws Exception {
        int databaseSizeBeforeUpdate = myFavoriteRepository.findAll().size();

        // Create the MyFavorite
        MyFavoriteDTO myFavoriteDTO = myFavoriteMapper.toDto(myFavorite);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restMyFavoriteMockMvc.perform(put("/api/my-favorites").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myFavoriteDTO)))
            .andExpect(status().isBadRequest());

        // Validate the MyFavorite in the database
        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteMyFavorite() throws Exception {
        // Initialize the database
        myFavoriteRepository.saveAndFlush(myFavorite);

        int databaseSizeBeforeDelete = myFavoriteRepository.findAll().size();

        // Delete the myFavorite
        restMyFavoriteMockMvc.perform(delete("/api/my-favorites/{id}", myFavorite.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<MyFavorite> myFavoriteList = myFavoriteRepository.findAll();
        assertThat(myFavoriteList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
